/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.isi.pegasus.planner.subworkflow.estimator;


import edu.isi.pegasus.common.util.DynamicLoader;
import edu.isi.pegasus.planner.classes.ADag;
import edu.isi.pegasus.planner.classes.PegasusBag;
import edu.isi.pegasus.planner.subworkflow.partitioner.DAXAbstraction;
import edu.isi.pegasus.planner.subworkflow.partitioner.SiteAbstraction;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author wchen
 */
public class EstimatorFactory {

    public static final String DEFAULT_ESTIMATOR = "Static";
    private static final String DEFAULT_ESTIMATOR_PATH =
            "edu.isi.pegasus.planner.subworkflow.estimator.implementation";


    public static EstimatorImplementation loadInstance( DAXAbstraction bigDax,
            SiteAbstraction site, ADag mDag, PegasusBag mBag, HashMap mJob2Time, String className)
    {
        Map estimatorMap  = new HashMap<String, String>();
        estimatorMap.put("static", "Static");
        estimatorMap.put("cputime", "CPUTime");
        estimatorMap.put("criticalpath", "CriticalPath");
        estimatorMap.put("heft", "HEFT");

        EstimatorImplementation estimator = null;
            //className = this.mBag.getPegasusProperties().getProperty("pegasus.subworkflow.estimator");
        if(className == null || className.equals(""))
            className = DEFAULT_ESTIMATOR;
        className = (String)estimatorMap.get(className.toLowerCase());
        className = (className.indexOf('.') == -1) ? DEFAULT_ESTIMATOR_PATH + "." + className : className;
        DynamicLoader dl = new DynamicLoader(className);
        //DAXAbstraction bigDax, SiteAbstraction site, ADag mDag, PegasusBag mBag
        Object argList[] = new Object[5];
        argList[0] = bigDax;
        if(site==null)
            site = new SiteAbstraction();
        argList[1] = site;
        argList[2] = mDag;
        argList[3] = mBag;
        argList[4] = mJob2Time;
        try
        {
            estimator = (EstimatorImplementation) dl.instantiate(argList);

        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        return estimator;
    }

}
